// src/router/index.jsx
import { createBrowserRouter } from 'react-router-dom';
import MainLayout from '../layout/MainLayout';
import Home from '../pages/Home';
import Dashboard from '../pages/dashboard/Dashboard';
import Overview from '../pages/dashboard/Overview';
import Analytics from '../pages/dashboard/Analytics';
import Users from '../pages/users/Users';
import UserList from '../pages/users/List';
import UserDetails from '../pages/users/Details';
import Login from '@/pages/Login';

const router = createBrowserRouter([
  {
    path: '/',
    element: <MainLayout />,
    children: [
      {
        index: true, // 默认子路由（访问 / 时显示）
        element: <Home />,
      },
      {
        path: 'dashboard',
        element: <Dashboard />,
        children: [
          {
            index: true, // 访问 /dashboard 时显示
            element: <Overview />,
          },
          {
            path: 'analytics', // 访问 /dashboard/analytics
            element: <Analytics />,
          },
        ],
      },
      {
        path: 'users',
        element: <Users />,
        children: [
          {
            index: true, // 访问 /users 时显示
            element: <UserList />,
          },
          {
            path: ':id', // 动态路由：访问 /users/123
            element: <UserDetails />,
          },
        ],
      },
    ],
  },
  {
    path: '/login',
    element: <Login />,
  },
  {
    path: '/*',
    element: <div>404</div>,
  },
]);

export const routes = [
  {
    path: '/',
    name: '首页',
  },
  {
    path: '/dashboard',
    name: '详情',
  },
  {
    path: '/dashboard/analytics',
    name: '分析',
  },
  {
    path: '/users',
    name: '用户列表',
  },
  {
    path: '/users/1231212',
    name: '用户信息',
  },
];

export default router;
